---------------------------------
-- 图片创建
----------------------------------
local M = {}

function M.newImageRect(params)
	local parent = params.parent
	local path = params.path
	local baseDir = params.baseDir
	local width = params.width
	local height = params.height

	local x, y = params.x, params.y
	local anchorX, anchorY = params.anchorX, params.anchorY

	local function fixParams()
		local imgParams = {}
		if parent then
			imgParams[#imgParams + 1] = parent
		end
		imgParams[#imgParams + 1] = path
		if baseDir then
			imgParams[#imgParams + 1] = baseDir
		end
		imgParams[#imgParams + 1] = width
		imgParams[#imgParams + 1] = height
		return imgParams
	end

	local imgParams = fixParams()

	local img = display.newImageRect(unpack(imgParams))

	layout.setXY(img, x, y)
	layout.setAnchor(img, anchorX, anchorY)

	return img
end

function M.newImage(params)
	local parent = params.parent
	local path = params.path
	local baseDir = params.baseDir

	local x, y = params.x, params.y
	local anchorX, anchorY = params.anchorX, params.anchorY

	local function fixParams()
		local imgParams = {}

		if parent then
			imgParams[#imgParams + 1] = parent
		end

		imgParams[#imgParams + 1] = path

		if baseDir then
			imgParams[#imgParams + 1] = baseDir
		end

		return imgParams
	end

	local imgParams = fixParams()
	local img = display.newImage(unpack(imgParams))

	layout.setXY(img, x, y)
	layout.setAnchor(img, anchorX, anchorY)

	return img
end

return M